package com.youi.web;

import java.text.ParseException;
import java.util.Date;
import java.util.List;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.youi.exception.BusinessException;
import com.youi.manage.HttpRequestManage;
import com.youi.common.DelStatus;
import com.youi.service.MerchantwithdrawdetailService;
import com.youi.entity.Merchantwithdrawdetail;
import com.youi.common.Common;
import com.youi.util.CommonInfoUtil;
import com.youi.util.DateUtil;
import com.youi.util.JsonUtil;
import com.youi.util.ObjectUtil;
import com.youi.util.Page;

/**
* 供应商提现申请表(对账单)明细控制层
* @author Administrator
*/
@Controller
public class MerchantwithdrawdetailController  extends HttpRequestManage{

		@Autowired
		private MerchantwithdrawdetailService merchantwithdrawdetailService;
	

		/**
		 * I-95
		 * 查询供应商提现申请表(对账单)明细列表
		*/
		@ResponseBody
		@RequestMapping("sysUserGetInfo/getMerchantwithdrawdetail")
		public String getMerchantwithdrawdetail(ModelMap modelMap,HttpServletRequest request) throws BusinessException,ParseException{
			Integer pageIndex=optInteger("pageIndex",request,1);
			Integer pageNum=optInteger("pageNum",request,10);
			Integer orderStatus=optInteger("orderStatus",request);
			Integer merchantStatus=optInteger("merchantStatus", request);
			Long merchantwithdrawId=getLong("id", request);
			String dateNo=optString("dateNo",request);
			String withdrawNo=optString("withdrawNo",request);
			String des=optString("des",request,Common.DESC);
			String pms=optString("pms",request);
			Date start=optDate("start",request,"yyyy-MM-dd HH:mm:ss");
			Date end=optDate("end",request,"yyyy-MM-dd HH:mm:ss");
			Map<String, Object> prams=new HashMap<String, Object>();
			prams.put(Common.DELSTATUS, DelStatus.NODEL);
			prams.put("merchantwithdrawId", merchantwithdrawId);
			//期号搜索
			if (dateNo!=null&&dateNo.trim().length()>0) {
				prams.put("dateNo", dateNo);
			}
			//提现单号
			if (withdrawNo!=null&&withdrawNo.trim().length()>0) {
				prams.put("withdrawNo", withdrawNo);
			}
			//订单状态
			if (orderStatus!=null) {
				prams.put("orderStatus", orderStatus);
			}
			//提现状态
			if (merchantStatus!=null) {
				prams.put("merchantStatus", merchantStatus);
			}
			Map<String, Object> sortPram=new HashMap<String, Object>();
			sortPram.put(Common.ID,des);
			Map<String, Object> searchPram=null;
			if (pms!=null) {
				searchPram=new HashMap<String, Object>();
			}
			Map<String, Object> startTime=null;
			if(start!=null){
				startTime=new HashMap<String, Object>();
				startTime.put("gmtOrder",start);
			}
			Map<String, Object> endTime=null;
			if(end!=null){
				endTime=new HashMap<String, Object>();
				endTime.put("gmtOrder",end);
			}
			List<Merchantwithdrawdetail> merchantwithdrawdetailList=merchantwithdrawdetailService.getByParamsList(prams, searchPram,sortPram,  (pageIndex-1)*pageNum, pageNum, startTime, endTime);
			if (merchantwithdrawdetailList==null||merchantwithdrawdetailList.size()==0) {
				return JsonUtil.toJson(CommonInfoUtil.NULLDATA, "空数据");
			}
			Integer pageCount=merchantwithdrawdetailService.getCountByParamss(prams, searchPram, startTime, endTime);
			modelMap.put(CommonInfoUtil.PAGECOUNT, Page.getCount(pageCount, pageNum));//pageCount  总页数
			modelMap.put(CommonInfoUtil.PAGEINDEX, pageIndex);			//pageIndex     查询页数
			modelMap.put(CommonInfoUtil.ALLCOUINT,pageCount);
			modelMap.put(CommonInfoUtil.DATA, merchantwithdrawdetailList);		//jsonObjectList json对象集合
			merchantwithdrawdetailService.getMerchantwithdrawdetailMsg(merchantwithdrawdetailList);
			return JsonUtil.toJson(CommonInfoUtil.SUCCESS, "操作完成",modelMap);
		}
		
		/**
		 * I-95-1
		 * 导出供应商提现申请表(对账单)明细列表excel
		*/
		@ResponseBody
		@RequestMapping("toMerchantwithdrawdetailExcel")
		public String toMerchantwithdrawdetailExcel(ModelMap modelMap,HttpServletRequest request) throws BusinessException,ParseException{			
			Integer orderStatus=optInteger("orderStatus",request);
			Integer merchantStatus=optInteger("merchantStatus", request);
			Long merchantwithdrawId=getLong("id", request);
			String dateNo=optString("dateNo",request);
			String withdrawNo=optString("withdrawNo",request);
			String des=optString("des",request,Common.DESC);
			String pms=optString("pms",request);
			Date start=optDate("start",request,"yyyy-MM-dd HH:mm:ss");
			Date end=optDate("end",request,"yyyy-MM-dd HH:mm:ss");
			Map<String, Object> prams=new HashMap<String, Object>();
			prams.put(Common.DELSTATUS, DelStatus.NODEL);
			prams.put("merchantwithdrawId", merchantwithdrawId);
			//期号搜索
			if (dateNo!=null&&dateNo.trim().length()>0) {
				prams.put("dateNo", dateNo);
			}
			//提现单号
			if (withdrawNo!=null&&withdrawNo.trim().length()>0) {
				prams.put("withdrawNo", withdrawNo);
			}
			//订单状态
			if (orderStatus!=null) {
				prams.put("orderStatus", orderStatus);
			}
			//提现状态
			if (merchantStatus!=null) {
				prams.put("merchantStatus", merchantStatus);
			}
			Map<String, Object> sortPram=new HashMap<String, Object>();
			sortPram.put(Common.ID,des);
			Map<String, Object> searchPram=null;
			if (pms!=null) {
				searchPram=new HashMap<String, Object>();
			}
			Map<String, Object> startTime=null;
			if(start!=null){
				startTime=new HashMap<String, Object>();
				startTime.put("gmtOrder",start);
			}
			Map<String, Object> endTime=null;
			if(end!=null){
				endTime=new HashMap<String, Object>();
				endTime.put("gmtOrder",end);
			}
			List<Merchantwithdrawdetail> merchantwithdrawdetailList=merchantwithdrawdetailService.getByParamsAll(prams, searchPram, sortPram, startTime, endTime);
			if (merchantwithdrawdetailList==null||merchantwithdrawdetailList.size()==0) {
				return JsonUtil.toJson(CommonInfoUtil.NULLDATA, "空数据");
			}
			merchantwithdrawdetailService.getMerchantwithdrawdetailMsg(merchantwithdrawdetailList);
			merchantwithdrawdetailService.toExcelMerchantwithdraw(request, merchantwithdrawdetailList);
			modelMap.put(CommonInfoUtil.JSONCODE, CommonInfoUtil.SUCCESS);
			modelMap.put(CommonInfoUtil.JSONMSG, "操作成功");
			return JsonUtil.toJson(CommonInfoUtil.SUCCESS, "操作完成",modelMap);
		}


		/**
		 * 查询所有供应商提现申请表(对账单)明细
		 * @param modelMap
		 * @param session
		 * @return
		 */
		@ResponseBody
		@RequestMapping("getAllMerchantwithdrawdetail")
		public String getAllMerchantwithdrawdetail(ModelMap modelMap,HttpServletRequest request) throws BusinessException{
			List<Merchantwithdrawdetail> merchantwithdrawdetailList= merchantwithdrawdetailService.getByParams(null);
			if (merchantwithdrawdetailList==null||merchantwithdrawdetailList.size()==0) {
				return JsonUtil.toJson(CommonInfoUtil.NULLDATA, "空数据");
			}
			return JsonUtil.toJson(CommonInfoUtil.SUCCESS, "操作完成",merchantwithdrawdetailList);//jsonObjectList	json对象集合
		}
}
